#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d",&a);
	b=a%100;//b=day
	a/=100;
	c=a%100;//c=month
	a/=100;//now,a==year 
	if(c<=12)
	{
		switch(c)
		{
			case 1:
				if(b<=31)
				{
					printf("%d",b);
				}
				else
				{
					printf("Invalid");
				}
			break; 
			case 3:
				if(b<=31)
				{
					if((a%4==0&&a%100!=0) ||a%400==0)
					{
						b=31+29+b;
						printf("%d",b);
					}
					else
					{
						b=31+28+b;
						printf("%d",b);
					}
				}
				else
				{
					printf("Invalid");
				}
			break;	
			case 5:
				if(b<=31)
				{
					if((a%4==0&&a%100!=0) ||a%400==0)
					{
						b=31+29+31+30+b;
						printf("%d",b);
					}
					else
					{
						b=31+28+31+30+b;
						printf("%d",b);
					}
				}
				else
				{
					printf("Invalid");
				}
			break;
			case 7:
				if(b<=31)
				{
					if((a%4==0&&a%100!=0) ||a%400==0)
					{
						b=31+29+31+30+31+30+b;
						printf("%d",b);
					}
					else
					{
						b=31+28+31+30+31+30+b;
						printf("%d",b);
					}
				}
				else
				{
					printf("Invalid");
				}
			break;
			case 8:
				if(b<=31)
				{
					if((a%4==0&&a%100!=0) ||a%400==0)
					{
						b=31+29+31+30+31+30+31+b;
						printf("%d",b);
					}
					else
					{
						b=31+28+31+30+31+30+31+b;
						printf("%d",b);
					}
				}
				else
				{
					printf("Invalid");
				}
			break;
			case 10:
				if(b<=31)
				{
					if((a%4==0&&a%100!=0) ||a%400==0)
					{
						b=31+29+31+30+31+30+31+31+30+b;
						printf("%d",b);
					}
					else
					{
						b=31+28+31+30+31+30+31+31+30+b;
						printf("%d",b);
					}
				}
				else
				{
					printf("Invalid");
				}
			break;
			case 12:
				if(b<=31)
				{
					if((a%4==0&&a%100!=0) ||a%400==0)
					{
						b=31+29+31+30+31+30+31+31+30+31+30+b;
						printf("%d",b);
					}
					else
					{
						b=31+28+31+30+31+30+31+31+30+31+30+b;
						printf("%d",b);
					}
				}
				else
				{
					printf("Invalid");
				}
			break;
			case 4:
				if(b<=30)
				{
					if((a%4==0&&a%100!=0) ||a%400==0)
					{
						b=31+29+31+b;
						printf("%d",b);
					}
					else
					{
						b=31+28+31+b;
						printf("%d",b);
					}
				}
				else
				{
					printf("Invalid");
				}
			break;
			case 6:
				if(b<=30)
				{
					if((a%4==0&&a%100!=0) ||a%400==0)
					{
						b=31+29+31+30+31+b;
						printf("%d",b);
					}
					else
					{
						b=31+28+31+30+31+b;
						printf("%d",b);
					}
				}
				else
				{
					printf("Invalid");
				}
			break;
			case 9:
				if(b<=30)
				{
					if((a%4==0&&a%100!=0) ||a%400==0)
					{
						b=31+29+31+30+31+30+62+b;
						printf("%d",b);
					}
					else
					{
						b=31+28+31+30+31+30+62+b;
						printf("%d",b);
					}
				}
				else
				{
					printf("Invalid");
				}
			break;
			case 11:
				if(b<=30)
				{
					if((a%4==0&&a%100!=0) ||a%400==0)
					{
						b=31+29+31+30+31+30+62+61+b;
						printf("%d",b);
					}
					else
					{
						b=31+28+31+30+31+30+62+61+b;
						printf("%d",b);
					}
				}
				else
				{
					printf("Invalid");
				}
			break;
			case 2: 
			    if((a%4==0&&a%100!=0) ||a%400==0)
			    {
			    	if(b<=29)
			    	{
			    		b=b+31;
			    		printf("%d",b);
					}
			    	else
			    	{
			    		printf("Invalid");
					}
				}
				else
				{
					if(b<=28)
					{
			    		b=b+31;
			    		printf("%d",b);
					}
					else
					{
						printf("Invalid");
					}
				}
			break;
			default:
				printf("Invalid");
		}
	}
	else
	{
		printf("Invalid");
	}
	return 0;
}
